package server

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"specifica_video_manage/client"
	"specifica_video_manage/model"
	"specifica_video_manage/utils"
)

type TaskServer struct {
}

func (t TaskServer) Index(c *gin.Context) {
	//fmt.Println("into index server")
	c.HTML(200, "task/index.html", gin.H{"taskid": utils.Common{}.GenerateRandomKey(10)})
}

func (t TaskServer) AddTask(c *gin.Context) {
	var task model.SingleTaskModel
	err := c.Bind(&task)
	if err != nil {
		fmt.Println("bind task catch error =", err.Error())
	}
	fmt.Printf("task info = %#v", task)
	if len(task.Account) > 0 {
		go client.MysqlTaskClient{}.CreateTask(&task)
	}
	c.Redirect(302, "/task/")
}

func (t TaskServer) AutoMigrate(c *gin.Context) {
	go client.MysqlTaskClient{}.AutoMigrate()
	c.Redirect(302, "/task/")
}
